package com.hs.communication.mqtt.consumer;

import com.hs.communication.common.message.MessageHandler;
import com.hs.communication.common.utils.ByteUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import static com.hs.communication.mqtt.config.MqttConfig.MQTT_DATA_NAME;

@Slf4j
@Component
public class Consumer {

//    @Resource
//    private Producer producer;

    @Resource
    private MessageHandler messageHandler;

    @RabbitListener(queues = MQTT_DATA_NAME)
    public void receiveMsg(Message message) {
//        String msg = new String(message.getBody());
//        log.info("接受到队列 消息:{}", msg);

//        System.out.println("接受到队列 消息=" + msg);

//        ProtocolUtil.resolveBytes(msg.getBytes());

//        String serial = UUID.randomUUID().toString();

        byte[] body = message.getBody();
        String hex = ByteUtil.bytesToHex(body);

        System.out.println("接受到队列 消息=" + hex);

        messageHandler.resolveBytes("mqtt", body);
//        producer.send(serial);
    }
}
